package MenuUnit
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.utils.Dictionary;

	//菜单管理器
	public class MenuManager
	{
		public static var GameStage:Sprite;
		public static var currentMenu:String;
		public static var RootScene:Sprite;
		public static var GameWidth:int;
		public static var GameHeight:int;
		private static var Menus:Dictionary;		
		
		public function MenuManager()			
		{			
		}
		
		public  static function GetMenu(_key:String):Menu
		{
			return Menus[_key];
		}
		
		public  static function Init(_parent:Sprite,_w:int,_h:int):void
		{
			Menus = new Dictionary();
			RootScene = new Sprite(); 
			_parent.addChild(RootScene);
			GameWidth = _w;
			GameHeight = _h;
			GameStage = _parent;
		}
		
		public  static function AddMenu(_value:Menu, _key:String,_x:int = 0,_y:int = 0):void
		{
			Menus[_key] = _value;
			_value.visible = false;
			_value.x = _x;
			_value.y = _y;	
			RootScene.addChild(_value);
		}
		
		public static function DelMenu(_key:String):void
		{
			RootScene.removeChild(Menus[_key]);
		}
		
		//切换菜单
		public static function SwitchMenu(_index:String):void
		{
			if (Menus[_index] != null)
			{
				var oldMenu:Menu = Menus[currentMenu];
				if (oldMenu != null)
				{
				   oldMenu.visible = false;
				   oldMenu.Deactivate();		
				}
				var current:Menu = Menus[_index];
				current.visible = true;
				current.Active();
				currentMenu = _index;
			}			
		}	
		
		
		public static function AddImgToMenu(_x:int,_y:int,_bmp:BitmapData):void
		{
			var currentMenu:Menu = Menus[currentMenu];
			var img:Bitmap = new Bitmap(_bmp);
			currentMenu.Add(img, _x, _y);
		}
	}
}